<?$this->extend("layout/default") ?>
<script>
$(document).ready(function(){
	var produits = <?=$produits?>;
	var charges = <?=$charges?>;
	
	var plot1 = $.jqplot('chart1', [produits,charges], {
		title:'Evolution Produits/Charges',
		series:[
			{
				showMarker:false,
				label: "Produits"
			},
			{
				showMarker:false,
				label: "Charges"
			}
		],
	    axesDefaults: {
	        tickRenderer: $.jqplot.CanvasAxisTickRenderer,
	        tickOptions: {
	          angle: -30,
	          fontSize: '10pt'
	        },
	        min: 0
	    },
	    legend: { 
		    show:true, 
		    location: 'ne' 
		},
	    axes: {
	      xaxis: {
	        renderer: $.jqplot.CategoryAxisRenderer
	      }
	    },
	    highlighter: {
	        show: true,
	        sizeAdjust: 7.5
	      },
	      cursor: {
	        show: false
	      }
	  });
});
</script>
<div class="corner mainBox" style="">
    <h3> Factures client en attente de paiement </h3>
    
    <table id="dash_t1">
        <thead>
            <tr>
              <th> Client </th>
              <th> Date échéance</th>
              <th> Montant TTC </th>
              <th></th>
            </tr>
        </thead>
        <?
        if(count($factures)>0){
	        foreach($factures as $facture){
	        	if(strtotime($facture->echeance) <= time()) $className = "red";
	        	else $className = "normal";
	        ?>
	        <tr class="<?=$className?>">
	            <td><?=$aContacts[$facture->contact_id]?></td>
	            <td><?=date("d-m-Y",strtotime($facture->echeance))?></td>
	            <td><?=$facture->montant_ttc?> &euro;</td>
	            <td>
	            	<?if(strtotime($facture->echeance) <= time()){?>
	            	<a href="/download/relance/<?=$facture->devis_id?>" target="_blank"><img src="/public/images/icons/relance.png" title="Imprimer lettre de relance"/></a>
	            	<?}?>
	            </td>
	        </tr>
	        <?
	        }}else{?>
	     <tr>
	     	<td colspan="4"><center> Aucune facture en attente </center></td>
	     </tr>
	     <?}?>
     </table>
</div>
<div class="corner mainBox" style="">
    <h3> Factures fournisseurs à payer </h3>
    
    <table id="t2" class="tableau">
        <thead>
            <tr>
              <th> Client </th>
              <th> Date échéance</th>
              <th> Montant TTC </th>
            </tr>
        </thead>
        <?if(count($factures_f)>0){
        foreach($factures_f as $facture){
	        	if(strtotime($facture->echeance) <= time()) $className = "red";
	        	else $className = "normal";
	        ?>
	        <tr class="<?=$className?>">
	            <td><?=$aFournisseurs[$facture->_fournisseur]?></td>
	            <td><?=date("d-m-Y",strtotime($facture->echeance))?></td>
	            <td><?=$facture->montant_ttc?> &euro;</td>
	        </tr>
	        <?
	        }
        }else{?>
        <tr>
        	<td colspan="3"><center><i> Aucune facture en attente </i></center></td>
        </tr>
        <? }?>
     </table>
</div>
<?php 
$balance_tot = ($ca_tot-$achats_tot);
$balance_year = ($ca_year-$achats_year);
$balance_month = ($ca_month-$achats_month);
$waiting = ($waiting_paiements - $waiting_charges);
?>
<table width="100%" id="resume">
	<tr>
		<td style="vertical-align:top;padding-top:15px;">
			<div class="mainBox corner" style="background:#FFF;padding-left:10px;padding-bottom:10px;">
				<h3 style="width:200px;"> Chiffre d'affaire : </h3>
				<span> Total : </span> <span class="ca"><?=$ca_tot?> &euro; </span><br/>
				<span> Année en cours : </span> <span class="ca"><?=$ca_year?> &euro;</span> <br/>
				<span> Mois en cours : </span> <span class="ca"><?=$ca_month?> &euro;</span> <br/>
				<span> En attente de paiement : </span> <span class="ca"><?=$waiting_paiements?> &euro;</span> <br/>
			
				<h3 style="width:200px;"> Achats : </h3>
					<span> Total : </span><span class="achats"> <?=$achats_tot?> &euro; </span><br/>
					<span> Année en cours : </span> <span class="achats"><?=$achats_year?> &euro; </span><br/>
					<span> Mois en cours : </span> <span class="achats"><?=$achats_month?> &euro; </span><br/>
					<span> En attente de paiement : </span> <span class="achats"><?=$waiting_charges?> &euro;</span> <br/>
				<h3 style="width:200px;"> Balance : </h3>
					<span> Total :</span>  <span class="<?=($balance_tot>=0)?"benef":"perte"?>"><?=$balance_tot?> &euro; </span><br/>
					<span> Année en cours : </span> <span class="<?=($balance_year>=0)?"benef":"perte"?>"><?=$balance_year?> &euro; </span><br/>
					<span> Mois en cours : </span> <span class="<?=($balance_month>=0)?"benef":"perte"?>"><?=$balance_month?> &euro;</span> <br/>
					<span> En attente : </span> <span class="<?=($waiting>=0)?"benef":"perte"?>"><?=$waiting?> &euro;</span> <br/>
					
			</div>
		</td>
		<td width="60%" style="vertical-align:top;padding-top:15px;"><div id="chart1" style="height:300px; width:100%;"></div></td>
	</tr>
</table>